package com.ibeeking.found.content.b.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.content.b.rest.service.IBroadcastCouponService;
import com.ibeeking.found.content.service.common.param.BroadcastCouponParam;
import com.ibeeking.found.content.service.common.query.BroadcastCouponPageQuery;
import com.ibeeking.found.content.service.common.query.BroadcastCouponQuery;

import com.ibeeking.found.content.service.common.vo.BroadcastCouponVO;

import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BroadcastController控制器
 * @Description
 * @Author ibeeking
 * @Date 2022-02-18 14:11
 **/
@RestController
@RequestMapping("/b/broadcast/v1/coupon")
public class BroadcastCouponController {

    @Resource
    private IBroadcastCouponService broadcastCouponServiceImpl;

    /**
     * --------货架优惠券
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "优惠券分页列表")
    @PostMapping(value = "/pageList")
    public Page<BroadcastCouponVO> goodsPageList(@RequestBody BroadcastCouponPageQuery pageQuery) {
        return broadcastCouponServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "优惠券列表")
    @PostMapping(value = "/list")
    public List<BroadcastCouponVO> couponList(@RequestBody BroadcastCouponQuery broadcastCouponQuery) {
        return broadcastCouponServiceImpl.list(broadcastCouponQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "优惠券添加")
    @PostMapping(value = "/add")
    public Boolean couponAdd(@RequestBody @Validated BroadcastCouponParam broadcastCouponParam) {
        return broadcastCouponServiceImpl.add(broadcastCouponParam);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "批量优惠券添加")
    @PostMapping(value = "/batchAdd")
    public Boolean couponBatchAdd(@RequestBody List<String> couponIds) {
        return broadcastCouponServiceImpl.batchAdd(couponIds);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "优惠券修改")
    @PostMapping(value = "/modify")
    public Boolean couponModify(@RequestBody @Validated BroadcastCouponParam broadcastCouponParam) {
        return broadcastCouponServiceImpl.modify(broadcastCouponParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "优惠券查看")
    @GetMapping(value = "/view/{id}")
    public BroadcastCouponVO couponView(@PathVariable("id") Long id) {
        return broadcastCouponServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "优惠券删除")
    @PostMapping(value = "/del/{id}")
    public Boolean couponDel(@PathVariable("id") Long id) {
        return broadcastCouponServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "优惠券状态修改")
    @PostMapping(value = "/changeStatus/{id}/{status}")
    public Boolean couponChangePublishStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return broadcastCouponServiceImpl.changePublishStatus(id, status);
    }
}
